/*
author:huanghaifang
Date:2020-06-19
 */

const user=require('../models/userModel');

var userModel=user.userModel;

//1.add的方法
async function addUser(user) {
    try{
        var user=await userModel.create(user);
        if(user=={}||user==undefined){
            return {success:false,msg:'用户保持失败'};
        }else{
            return {success:true,user:user};
        }
    }catch(error){
        console.log('add user is error--error reason:'+error);
        return {success:false,msg:error};
    }
}
//2.findByName的方法
async function findByName(name) {
    try{
        var user=await userModel.findOne({name:name});
        if(user==undefined||user=={}){
            return {success:false,msg:'查无此人'};
        }else{
            return {success:true,user:user};
        }
    }catch(e){
        return {success:false,msg:e};
    }
}

exports.addUser=addUser;
exports.findByName=findByName;
